package cn.yshujia.controller;

import cn.yshujia.annotation.RateLimiter;
import cn.yshujia.domain.vo.ApiVO;
import cn.yshujia.service.impl.LikeServiceImpl;
import cn.yshujia.utils.JwtTokenUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YShuJia
 * @create 2024/4/23
 * @description 控制器
 */

@RestController
@Tag (name = "Like", description = "点赞Api")
public class LikeController {
	
	@Resource
	private LikeServiceImpl service;
	
	@PutMapping ("/like/update")
	@Operation (summary = "点赞")
	@RateLimiter
	@PreAuthorize ("@sys.hasOnePermission('like:all', 'like:update')")
	public ApiVO<Boolean> updateCount(Long sourceId, HttpServletRequest req) {
		Long userId = JwtTokenUtils.getUserId(req);
		return ApiVO.success(service.updateLikeCount(userId, sourceId));
	}
}

